/**
 * Copyright (C), 2015-2020, 东华云有限公司
 * FileName: PageListUtils
 * Author:   Hezeyu
 * Date:     2020/5/27 15:01
 * Description: 分页工具类
 * History:
 * <author>          <time>          <version>          <desc>
 * Hezeyu           2020/5/27 15:01   1.0              分页工具类
 */
package com.example.spring.security.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 〈分页工具类〉
 *
 * @author Hezeyu
 * @create 2020/5/27
 * @since 1.0.0
 */
@Data
@ApiModel(value = "分页实体",description = "分页使用的实体类")
public class PageUtils<T> {

    /**
     * 总条数
     */
    @ApiModelProperty(value = "总条数",name = "total",required = false)
    private Long total;

    /**
     * 当前页面条数
     */
    @ApiModelProperty(value = "当前页面条数",name = "size",required = true,example = "10")
    @NotNull(message = "当前页码不能为空")
    private Long size;
    /**
     * 当前页码
     */
    @ApiModelProperty(value = "当前页码",name = "current",required = true,example = "1")
    @NotNull(message = "当前页码不能为空")
    private Long current;

    /**
     * 返回参数
     */
    @ApiModelProperty(value = "返回参数",name = "records",required = false)
    private List<T> records;

    public PageUtils toPageUtis(IPage<T> page) {
        if(page!=null){
            this.total = page.getTotal();
            this.size = page.getSize();
            this.current = page.getCurrent();
            this.records = page.getRecords();
        }
        return this;
    }
}
